'=======================================
' 执行所有测试 case
'=======================================
Public Sub test_all_case()
    ' joinElem 测试
    test_joinElem
    ' removeAllCollection 测试
    test_removeAllCollection
    ' toVariantArray 测试
    test_toVariantArray
    ' cloneCollection 测试
    test_cloneCollection
    ' indexOf 测试
    test_indexOf
    ' mergePrimitiveVal 测试
    test_mergePrimitiveVal
    ' mergeObjVal 测试
    test_mergeObjVal
    ' addAllCollection 测试
    test_addAllCollection
    ' addIfNecessaryForPrimitive 测试
    test_addIfNecessaryForPrimitive
    ' addIfNecessaryForObj 测试
    test_addIfNecessaryForObj
End Sub

'=======================================
' 各方法的测试 case
'=======================================
' joinElem 测试
Private Sub test_joinElem()
    Dim a As New Collection
    a.Add "aaa"
    a.Add "bbb"
    a.Add "ccc"
    
    Dim result As String
    
    result = UtilsCollection.joinElem(a, ",")
    
    Debug.Assert result = "aaa,bbb,ccc"
End Sub

' removeAllCollection 测试
Private Sub test_removeAllCollection()
    Dim v3 As Collection
    Set v3 = New Collection

    Dim c As Collection
    Set c = New Collection
    c.Add "v1", "k1"
    c.Add "v2", "k2"
    c.Add v3, "k3"

    Debug.Assert c.Count = 3

    ' 清空 collection
    UtilsCollection.removeAllCollection c

    Debug.Assert c.Count = 0
End Sub

' toVariantArray 测试
Private Sub test_toVariantArray()
    Dim c As Collection
    Set c = New Collection
    c.Add "v1", "k1"
    c.Add "v2", "k2"
    Dim c2 As Collection
    Set c2 = New Collection

    c.Add c2, "k3"

    Dim arr As Variant
    arr = UtilsCollection.toVariantArray(c)
    Debug.Assert arr(0) = "v1"
    Debug.Assert arr(1) = "v2"
    Debug.Assert arr(2) Is c2
End Sub

' cloneCollection 测试
Private Sub test_cloneCollection()
    Dim a As Collection
    Set a = New Collection
    a.Add "aaa"
    a.Add "bbb"
    a.Add "ccc"

    Dim desc As Collection
    Set desc = UtilsCollection.cloneCollection(a)

    Debug.Assert desc.Count = 3
    Debug.Assert desc.Item(1) = "aaa"
    Debug.Assert desc.Item(2) = "bbb"
    Debug.Assert desc.Item(3) = "ccc"
End Sub

' indexOf 测试
Private Sub test_indexOf()
    ' 1. 在对象类型集合中进行搜索
    Dim src As Collection
    Set src = New Collection
    
    Dim c1 As Collection
    Set c1 = New Collection
    Dim c2 As Collection
    Set c2 = New Collection
    Dim c3 As Collection
    Set c3 = New Collection
    Dim c4 As Collection
    Set c4 = New Collection

    src.Add c1
    src.Add c2
    src.Add c3

    Debug.Assert UtilsCollection.indexOf(src, c1) = 1
    Debug.Assert UtilsCollection.indexOf(src, c2) = 2
    Debug.Assert UtilsCollection.indexOf(src, c3) = 3
    Debug.Assert UtilsCollection.indexOf(src, c4) = -1

    ' 2. 在基础数据类型集合中进行搜索
    Set src = New Collection
    
    src.Add "c1"
    src.Add "c2"
    src.Add "c3"

    Debug.Assert UtilsCollection.indexOf(src, "c1") = 1
    Debug.Assert UtilsCollection.indexOf(src, "c2") = 2
    Debug.Assert UtilsCollection.indexOf(src, "c3") = 3
    Debug.Assert UtilsCollection.indexOf(src, "c4") = -1
End Sub

' mergePrimitiveVal 测试
Private Sub test_mergePrimitiveVal()
    Dim a As Collection
    Set a = New Collection
    a.Add "a"
    a.Add "b"
    a.Add "c"
    
    Dim b As Collection
    Set b = New Collection
    b.Add "a"
    b.Add "b"
    b.Add "d"
    b.Add "d"
    b.Add "d"
    UtilsCollection.mergePrimitiveVal a, b

    Debug.Assert a.Count = 4
    Debug.Assert a.Item(1) = "a"
    Debug.Assert a.Item(2) = "b"
    Debug.Assert a.Item(3) = "c"
    Debug.Assert a.Item(4) = "d"
End Sub

' mergeObjVal 测试
Private Sub test_mergeObjVal()
    Dim c1 As Collection
    Set c1 = New Collection
    Dim c2 As Collection
    Set c2 = New Collection
    Dim c3 As Collection
    Set c3 = New Collection
    Dim c4 As Collection
    Set c4 = New Collection

    '---------------------------
    Dim a As Collection
    Set a = New Collection
    a.Add c1
    a.Add c2
    a.Add c3
    
    Dim b As Collection
    Set b = New Collection
    b.Add c1
    b.Add c2
    b.Add c4
    b.Add c3
    b.Add c4
    UtilsCollection.mergeObjVal a, b

    Debug.Assert a.Count = 4
    Debug.Assert a.Item(1) Is c1
    Debug.Assert a.Item(2) Is c2
    Debug.Assert a.Item(3) Is c3
    Debug.Assert a.Item(4) Is c4
End Sub

' addAllCollection 测试
Private Sub test_addAllCollection()
    Dim a As Collection
    Set a = New Collection
    a.Add "a"
    a.Add "b"
    a.Add "c"

    Dim b As Collection
    Set b = New Collection
    b.Add "a"
    b.Add "c"
    b.Add "d"
    b.Add "d"

    UtilsCollection.addAllCollection a, b

    Debug.Assert a.Item(1) = "a"
    Debug.Assert a.Item(2) = "b"
    Debug.Assert a.Item(3) = "c"
    Debug.Assert a.Item(4) = "a"
    Debug.Assert a.Item(5) = "c"
    Debug.Assert a.Item(6) = "d"
    Debug.Assert a.Item(7) = "d"
End Sub

' addIfNecessaryForPrimitive 测试
Private Sub test_addIfNecessaryForPrimitive()
    Dim a As Collection
    Set a = New Collection
    a.Add "a"
    a.Add "b"
    a.Add "c"

    UtilsCollection.addIfNecessaryForPrimitive a, "b"
    UtilsCollection.addIfNecessaryForPrimitive a, "d"

    Debug.Assert a.Item(1) = "a"
    Debug.Assert a.Item(2) = "b"
    Debug.Assert a.Item(3) = "c"
    Debug.Assert a.Item(4) = "d"
End Sub

' addIfNecessaryForObj 测试
Private Sub test_addIfNecessaryForObj()
    Dim c1 As Collection
    Set c1 = New Collection
    Dim c2 As Collection
    Set c2 = New Collection
    Dim c3 As Collection
    Set c3 = New Collection
    Dim c4 As Collection
    Set c4 = New Collection
    '---------------------------
    Dim a As Collection
    Set a = New Collection
    a.Add c1
    a.Add c2
    a.Add c3

    UtilsCollection.addIfNecessaryForObj a, c3
    UtilsCollection.addIfNecessaryForObj a, c4

    Debug.Assert a.Item(1) Is c1
    Debug.Assert a.Item(2) Is c2
    Debug.Assert a.Item(3) Is c3
    Debug.Assert a.Item(4) Is c4
End Sub

